package com.yan.test.work.testpaging3

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.yan.test.work.testpaging3.databinding.LayoutDataItemBinding

/**
 * Create By : 'YWY'
 * On : 2024/4/5
 */
class KTLAdapter:PagingDataAdapter< DataBean , KTLAdapter.VH>(object: DiffUtil.ItemCallback<DataBean>(){
    override fun areItemsTheSame(oldItem: DataBean, newItem: DataBean): Boolean = oldItem.objID == newItem.objID

    @SuppressLint("DiffUtilEquals")
    override fun areContentsTheSame(oldItem: DataBean, newItem: DataBean): Boolean = oldItem == newItem
}) {



    inner class VH(val binding: LayoutDataItemBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.binding.data = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return  VH(LayoutDataItemBinding.inflate(LayoutInflater.from(parent.context) , parent , false))
    }

}